import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/reset.css';
import WujieVue from "wujie-vue3"
import router from './router/index.ts'

const { setupApp, preloadApp, bus } = WujieVue

// 预加载子应用
preloadApp({
  name: "subapp",
  url: "http://localhost:8082",
  fetch: (url: RequestInfo, options?: RequestInit) => {
    return window.fetch(url, options || {})
  },
})

// 设置子应用配置
setupApp({
  name: "subapp",
  url: "http://localhost:8082",
  exec: true,
  sync: true,
  fetch: (url: RequestInfo, options?: RequestInit) => {
    return window.fetch(url, options || {})
  },
  plugins: [
    {
      htmlLoader: (code: string) => {
        // console.log('HTML 加载器被调用')
        return code
      },
      jsBeforeLoaders: [
        {
          callback: (appWindow: Window) => {
            // console.log('JS 前置加载器被调用')
          }
        }
      ],
      jsLoader: (code: string, url: string) => {
        // console.log('JS 加载器被调用:', url)
        return code
      },
      cssBeforeLoaders: [],
      cssLoader: (code: string, url: string) => {
        // console.log('CSS 加载器被调用:', url)
        return code
      }
    }
  ]
})

const app = createApp(App);
app.use(Antd);
app.use(WujieVue);
app.use(router);

app.mount('#app')